/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import request from '@/utils/request';
import { isArray } from 'lodash';

export interface OrderItem {
  account: string;
  created_at: string;
  delivery_accept_time: string;
  delivery_brand_name: string;
  delivery_order_no: string;
  id: string;
  order_desc: string;
  receiver_address: string;
  shop_name: string;
  source_brand_name: string;
  source_order_no: string;
  sh_phone: string;
}

export interface SearchParams {
  create_day?: string;
  status: string;
  account?: string;
  sh_phone?: string;
  source_order_no?: string;
  delivery_order_no?: string;
  page: string;
  size: string;
}

export interface DeliveryLogItem {
  brand_name: string;
  delivery_no: string;
  delivery_account: string;
  cancel: {
    created_at: string;
    log_desc: string;
  };
  create: {
    created_at: string;
    log_desc: string;
  };
  delivery_type: string;
  orderback: {
    created_at: string;
    log_desc: string;
  }[];
  status_desc: string;
  status: string;
  delivery_brand: string;
  order_id: string;
}

export interface Operate {
  created_at: string;
  id: string;
  info: string;
  order_id: string;
  user_id: string;
}

export interface JdkOrderDetail {
  account: string;
  booking: string;
  created_at: string;
  delivery_accept_time: string;
  delivery_brand_name: string;
  delivery_order_no: string;
  delivery_type: string;
  distance: string;
  good_info: string;
  id: string;
  league_id: string;
  league_name: string;
  is_league: string;
  order_remark: string;
  sh_info: string;
  shop_info: string;
  shop_name: string;
  source_brand_name: string;
  source_name: string;
  source_order_no: string;
  order_desc: string;
  sender_address: string;
  sender_name: string;
  sender_phone: string;
  delivery_fee_list: any[];
}

export interface PayLog {
  created_at: string;
  desc: string;
}

/**
 * 聚单客订单列表
 *  */
export async function getJdkOrderList(params: SearchParams): Promise<any> {
  return request('/jdk/order/list', {
    method: 'POST',
    data: params,
  }).then(({ data }) => {
    const { list, total, page } = data || {};
    if (isArray(list) && list.length > 0) {
      return {
        total,
        success: true,
        data: list,
        current: Number(page),
      };
    }
    return {};
  });
}

/**
 * 聚单客订单详情
 *  */
export async function getJdkOrderDetail(params: { id: string }) {
  return request('/jdk/order/detail', {
    method: 'POST',
    data: params,
  });
}

/**
 * 聚单客订单详情，取消运力
 *  */
export async function jdkCancelOrder(params: { order_id: string; delivery_brand: string }) {
  return request('/jdk/order/cancelByDeliveryBrand', {
    method: 'POST',
    data: params,
  });
}

/**
 * 聚单客结束订单
 *  */
export async function editOrderDelivery(params: any) {
  return request('/jdk/order/editOrderDelivery', {
    method: 'POST',
    data: params,
  });
}
